package com.warm.pump.module.sys.service.impl;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.module.sys.bean.po.gen.DictDyna;
import com.warm.pump.module.sys.dao.gen.DictDynaDao;
import com.warm.pump.module.sys.service.IDictDynaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("DictDynaService")
@CacheConfig(cacheNames = "DictDyna")
public class DictDynaServiceImpl implements IDictDynaService {
    @Autowired
    private DictDynaDao dictDynaDao;

    @Override
    public DictDyna queryObject(Long id) {
        return dictDynaDao.selectByPrimaryKey(id);
    }

    @Cacheable(key = "targetClass + methodName +#p0")
    public DictDyna queryObject(Map<String, Object> map) {
        return dictDynaDao.selectByMap(map);
    }

    @Override
    public List<DictDyna> queryList(Map<String, Object> map) {
        return dictDynaDao.getListByMap(map);
    }

    @Override
    public PageBean getPageBeanByMap(Map map, int pageNo, int pageSize) {
        return dictDynaDao.getPageBeanByMap(map, pageNo, pageSize);
    }


    @Override
    public int queryTotal(Map<String, Object> map) {
        return dictDynaDao.countTotalByMap(map);
    }

    @Override
    public void save(DictDyna dictDyna) {
        dictDynaDao.insertSelective(dictDyna);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void update(DictDyna dictDyna) {
        dictDynaDao.updateByPrimaryKeySelective(dictDyna);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void delete(Long id) {
        dictDynaDao.deleteByPrimaryKey(id);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void delete(Map<String, Object> map) {
        dictDynaDao.deleteByMap(map);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void deleteBatch(Long[] ids) {
        Map<String, Object> map = new HashMap<>();
        map.put("id_in", ids);
        dictDynaDao.deleteByMap(map);
    }

}
